@extends('admin.layouts.admin')
@section('content')
    <div class="layui-form" lay-filter="LAY-edit-forms" id="LAY-edit" style="padding: 20px 20px;background-color: #fff;">
        <div class="layui-tab">
            <ul class="layui-tab-title">
                @foreach($config_tab as $val)
                    <a href="/admin/setting_config_page/index?tab_id={{$val['value']}}&type={{$val['type']}}"><li @if($tab_id == $val['value'])class="layui-this" @endif>{{$val['label']}}</li></a>
                @endforeach
            </ul>
            <div class="layui-tab-content"></div>
        </div>
        <div class="one-page-width">
            @foreach($list as $data)
                @switch($data['type'])
                    @case('text'){{--文本框--}}
                        @include('admin.setting_config_page._text')
                        @break

                    @case('textarea'){{--多行文本框--}}
                        @include('admin.setting_config_page._textarea')
                        @break

                    @case('radio'){{--单选框--}}
                        @include('admin.setting_config_page._radio')
                        @break

                    @case('checkbox')
                        @include('admin.setting_config_page._checkbox')
                        @break

                    @case('select')
                        @include('admin.setting_config_page._select')
                        @break

                    @case('upload')
                        @include('admin.setting_config_page._upload',['id'=>$data['id']])
                        @break

                    @default


                @endswitch

            @endforeach
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="LAY-edit-forms" id="LAY-edit-forms" value="确认">
            </div>
        </div>
    </div>

@endsection
@section('scripts')
    <script>
        layui.config({
            base: '../' //静态资源所在路径
        }).use([ 'table', 'form','upload'], function(){
            var $ = layui.$
                ,form = layui.form
                ,upload = layui.upload ;


            //普通图片上传
            // var eleId = "#test-upload-normal";
            // var postUrl = "/admin/file/upload";
            // var layUpload = upload;
            // Common.uploadFile(eleId, postUrl, layUpload, "#test-upload-normal-img")

            form.on("submit(LAY-edit-forms)", function(e) {
                var mod = e.field;
                console.log(mod)

                $.ajax({
                    type:"post",
                    url:"{{ route('admin.setting_config_page.update') }}",
                    data:mod,
                    headers:{
                        'X-CSRF-TOKEN': layui.$('meta[name="csrf-token"]').attr('content')
                    },
                    error:function(){
                        Common.systemReturn('系统错误')
                    },
                    success:function(data){
                        if(data.code == 0){
                            Common.successReturn(data)
                        }else{
                            Common.errorReturn(data)
                        }
                    }
                });

            })

        });//use

    </script>
@stop
